package Week3.J0429;

// 原方案双重for循环超时, 应该需要用滑动窗口

public class 最长无重复子数组_xv {
    public static void main(String[] args) {
        int[] arr = {2,2,3,4,8,99,3};
        System.out.println(maxLength(arr));
    }
    public static int maxLength (int[] arr) {
        int[] hash = new int[100000];
        int left = 0;
        int right = 0;
        int sum = 0;
        int n = arr.length;

        while (right < n)  {
            hash[arr[right]]++;
            while (hash[arr[right]] > 1) {
                hash[arr[left]]--;
                left++;
            }
            sum = Math.max(sum, right-left+1);
            right++;
        }
        return sum;
    }
}
